﻿CREATE PROCEDURE [audit].[GetTraceFileFolder]
@FilePath NVARCHAR (2000) OUTPUT
AS
BEGIN
	CREATE TABLE #XP_OUTPUT(
		[Value] nvarchar(2000) COLLATE DATABASE_DEFAULT
		,[Data] nvarchar(2000) COLLATE DATABASE_DEFAULT
	)
	
	INSERT #XP_OUTPUT ([Value],[Data])
	EXEC master.dbo.xp_instance_regread
		N'HKEY_LOCAL_MACHINE',
		N'Software\Microsoft\MSSQLServer\Setup',
		N'SQLPath'

	SELECT @FilePath = Data + '\LOG'
	FROM #XP_OUTPUT

	DROP TABLE #XP_OUTPUT

	IF(@FilePath IS NULL)
	BEGIN
		RAISERROR('RegOpenKeyEx() returned error 2, ''The system cannot find the file specified.''',16,1)
		RETURN(1)
	END

	RETURN(0)
END